<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>渠道审核</title>
    <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
</head>
<body>
     <div class="easyui-container-fluid">
         <div class="easyui-panel" style="border:none;">
             <div class="nav" id="nav"></div>
             <div class="easyui-panel" style="border:none;">
                 <form id="ff">
                     <div style="margin-bottom:20px;">
                         <label class="item-label">年份：</label>
                         <input type="text" class="easyui-combobox" name="year" id="year" style="width:100px;"/>
                         <span id="monthLabel">
	                         <label class="item-label">月份：</label>
	                         <input type="text" class="easyui-combobox" name="month" id="month" style="width:100px;"/>
                     	</span>
                     	<span id="weekLabel">
	                         <label class="item-label">周数：</label>
	                         <input type="text" class="easyui-combobox" name="week" id="week" style="width:100px;"/>
                     	</span>
                         <label class="item-label">渠道：</label>
                         <input type="text" class="easyui-combobox" id="channel" name="channelCode"  style="width:100px;"/>
                         <a href="javascript:void(0);" style="margin-left:15px;width:80px;" class="easyui-linkbutton" onclick="searchBy()">查询</a>
                     </div>
                     <div style="margin-bottom:10px;margin-left: 10px;text-align:left;">
                     	<div>
                     		<span id="periodInfo" style="font-weight: bold;font-size: 16px;margin-right: 10px;"></span>
                     		<span id="dataGatherer"></span>
                     	</div>
                     	门店数量统计--实报门店数：<span id="realMallCount" style="margin-right:10px;font-weight: bold;font-size: 16px;"></span>
                     	应报门店数：<span id="expectMallCount" style="margin-right:10px;font-weight: bold;font-size: 16px;"></span>
                     </div>
                 </form>
             </div>
             <div class="table-wrapper">
                 <table id="datagrid" class="easyui-datagrid" data-options="scrollbarSize:0">
                     <thead>
                        <tr>
                            <th data-options="field:'mallCode',align:'center'" width="10%">商场代码</th>
                            <th data-options="field:'mallName',align:'center'" width="30%">商场名称</th>
                            <th data-options="field:'lastYearSalesCount',align:'center'" width="10%" formatter="formatSalesCount">同期</th>
                            <th data-options="field:'lastBeforeSalesCount',align:'center'" width="10%" formatter="formatSalesCount">上上月（周）</th>
                            <th data-options="field:'lastSalesCount',align:'center'" width="10%" formatter="formatSalesCount">上月（周）</th>
                            <th data-options="field:'salesCount',align:'center'" width="10%">本月（周）</th>
                        </tr>
                     </thead>
                 </table>
             </div>
         </div>
     </div>
     <script type="text/javascript">
         $(function(){
             setNav();
             initChannelSelect("channel");
             initMonthWeek("monthLabel","weekLabel");
             $("#datagrid").datagrid({
                 // pagination:true,
                 rownumbers:true
             });
         });
         
         function searchBy(){
             if (!isOfflineType()) {
                 alert("该功能只支持线下模式");
                 return;
             }

        	 if(!$('#channel').val()){
        		 alert('请选择渠道');
        		 return false;
        	 }
        	 var periodInfo = '';
        	 periodInfo += $('#year').val()+'年';
        	 if(window.parent.workMode=='month'){
                 periodInfo += $('#month').val()+'月';
        	 }else{
                 periodInfo += $('#week').val()+'周';
        	 }
        	 periodInfo += '('+$('#channel').combobox('getText')+')';
        	 $('#periodInfo').html(periodInfo);
             var data = getFormData(document.getElementById("ff"));
             $.ajax({
                  url:config.url + "/channelCheck/mall/data",
                  type:"get",
                  data:transfer(data),
                  xhrFields:{withCredentials:true},
                  beforeSend:function () {
                      $.messager.progress({
                          title:"请稍等",
                          interval:50,
                          text:"数据加载中..."
                      });
                    },
                  success:function(data){
                	  if(data.mallReportList && data.mallReportList.length>0){
	                	  $("#datagrid").datagrid({data: data.mallReportList}).datagrid("getPager");
                	  }else{
	                	  $("#datagrid").datagrid({data: []}).datagrid("getPager");
                	  }
                	  $('#dataGatherer').html('渠道数据联系人：'+(data.dataGatherer?data.dataGatherer:'暂无'));
                	  $('#realMallCount').html(data.realMallCount);
                	  $('#expectMallCount').html(data.expectMallCount);
                	  
                	  $.messager.progress("close");
                  },
                  error:function(data){
                     console.log(data);
                     $.messager.progress("close");
                  }
              });
          }
         
		function formatSalesCount(val, row) {
			var plus = '';
			if(val<=0 || row.salesCount==val){
				plus = '<span style="color:#FF0000;"">(--)</span>';
			}else{
				if(row.salesCount-val>0){
					plus = '<span style="color:#FF0000;"">(';
					plus = '+' + (row.recordCount-val) + '|';
					plus = '+' + (row.salesCount-val)*100/val + '%';
					plus = ')</span>';
				}else if(row.salesCount-val<0){
					plus = '<span style="color:#009900;"">(';
					plus = '-' + (val-row.salesCount) + '|';
					plus = '-' + (val-row.salesCount)*100/val + '%';
					plus = ')</span>';
				}
			}
			
			return '<span style="color:#333333;">' + val + '</span>' + plus;
		}
	</script>
</body>
</html>